import axios from 'axios'
import { ElMessage } from 'element-plus'

const request = axios.create({
	baseURL: '',
	timeout: 6000
})

request.interceptors.request.use(
	(config) => {
		config.headers['Authorization'] = ''
		return config
	},
	(error) => {
		return Promise.reject(error.message)
	}
)

request.interceptors.response.use(
	(response) => {
		const data = response.data
		return Promise.resolve(data)
	},
	(error) => {
		ElMessage({
			message: '请求服务器失败',
			type: 'error'
		})
		return Promise.reject(error.message)
	}
)

const Get = () => request.get(url, { params }, (config = {}))
const Post = () => request.post(url, params, (config = {}))
const Put = () => request.put(url, { params }, (config = {}))
const Delete = () => request.delete(url, params, (config = {}))

export { Get, Post, Put, Delete }
